import 'package:serverpod/serverpod.dart';
import 'package:serverpod_auth_core_server/src/session/session.dart';
import 'package:test/test.dart';

void main() {
  final authUserId = const Uuid().v4obj();

  group('Given an `AuthenticationInfo` with a UUID `authId`', () {
    final authId = const Uuid().v4obj();

    final authenticationInfo = AuthenticationInfo(
      authUserId.uuid,
      {},
      authId: authId.uuid,
    );

    test(
      'when reading the `serverSideSessionId` field, then the UUID is returned.',
      () {
        expect(authenticationInfo.serverSideSessionId, authId);
      },
    );
  });

  group('Given an `AuthenticationInfo` with a non-UUID `authId`', () {
    final authenticationInfo = AuthenticationInfo(
      '123',
      {},
      authId: 'foo-bar',
    );

    test('when reading the `serverSideSessionId` field, then it throws.', () {
      expect(
        () => authenticationInfo.serverSideSessionId,
        throwsFormatException,
      );
    });
  });
}
